package com.ymt.order.controller;

import com.ymt.enums.PayType;
import com.ymt.order.service.OrderService;
import com.ymt.producer.domain.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;

public class PayOrderThred implements Runnable {
    private static final Logger LOGGER = LoggerFactory.getLogger(PayOrderThred.class);
    private static final BigDecimal PAYPRICE = BigDecimal.TEN;

    private PayType payType;
    private OrderService orderService;

    private PayOrderThred(PayType payType, OrderService orderService) {
        this.payType = payType;
        this.orderService = orderService;
    }

    public static PayOrderThred create(PayType payType, OrderService orderService) {
        return new PayOrderThred(payType, orderService);
    }

    @Override
    public void run() {
        for (int i = 0; i < 200; i++) {
            Order order = new Order();
            order.setPayType(payType.getPayKey());
            order.setOrderPrice(PAYPRICE);
            orderService.payOrder(order);
            LOGGER.info("【业务提供方】{}支付回调!金额:{}", payType.getPayName(), PAYPRICE);

            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
